import logging

from playwright.sync_api import Page

from framework.SuperClass import SuperClass


class DeployCommandManager(SuperClass):

    def uploadPdfFiel(self, pdfFileAbsoultPath: str):
        page = self.page
        # Click ul[role="menu"] div:has-text("动员命令管理")
        page.click("ul[role=\"menu\"] div:has-text(\"动员命令管理\")")
        # Click a:has-text("创建动员命令")
        page.click("a:has-text(\"创建动员命令\")")
        page.set_input_files(
            "#app > section > section > main > div:nth-child(3) > div > div > div > div > div > div > div > div:nth-child(2) > div > div > div > div > div > fieldset:nth-child(1) > form > div > div:nth-child(1) > div > div.ant-col.ant-col-xs-24.ant-col-sm-12.ant-form-item-control-wrapper > div > span > span > div.ant-upload.ant-upload-select.ant-upload-select-text > span > input[type=file]",
            pdfFileAbsoultPath)

        # Click button:has-text("解析命令文件")
        page.click("button:has-text(\"解析命令文件\")")
        # Click button:has-text("下一步")
        page.click("button:has-text(\"下一步\")")
        # 删除不要的命令
        for i in range(2, 9):
            page.click("//*[@id='app']/section/section/main/div[2]/div/div/div/div/div/div/div/div[2]/div/div/div[1]/div/div/div/div/div[2]/div/div/table/tbody/tr[1]/td/span/a[1]")
            # Click button:has-text("确 定")
            page.click("button:has-text(\"确 定\")")

        # Click .ant-table-body-inner .ant-table-fixed .ant-table-tbody .ant-table-row.ant-table-row-hover .ant-table-row-cell-break-word span a:nth-child(3)
        page.click(
            ".ant-table-body-inner .ant-table-fixed .ant-table-tbody .ant-table-row.ant-table-row-hover .ant-table-row-cell-break-word span a:nth-child(3)")
        # Click button:has-text("确 定")
        page.click("button:has-text(\"确 定\")")
        # Click .ant-table-body-inner .ant-table-fixed .ant-table-tbody .ant-table-row.ant-table-row-hover .ant-table-row-cell-break-word span a:nth-child(3)
        page.click(
            ".ant-table-body-inner .ant-table-fixed .ant-table-tbody .ant-table-row.ant-table-row-hover .ant-table-row-cell-break-word span a:nth-child(3)")
        # Click button:has-text("确 定")
        page.click("button:has-text(\"确 定\")")
        # Click .ant-table-body-inner .ant-table-fixed .ant-table-tbody .ant-table-row.ant-table-row-hover .ant-table-row-cell-break-word span a:nth-child(3)
        page.click(
            ".ant-table-body-inner .ant-table-fixed .ant-table-tbody .ant-table-row.ant-table-row-hover .ant-table-row-cell-break-word span a:nth-child(3)")
        # Click button:has-text("确 定")
        page.click("button:has-text(\"确 定\")")
        # Click .ant-table-body-inner .ant-table-fixed .ant-table-tbody .ant-table-row.ant-table-row-hover .ant-table-row-cell-break-word span a:nth-child(3)
        page.click(
            ".ant-table-body-inner .ant-table-fixed .ant-table-tbody .ant-table-row.ant-table-row-hover .ant-table-row-cell-break-word span a:nth-child(3)")
        # Click button:has-text("确 定")
        page.click("button:has-text(\"确 定\")")
        # Click .ant-table-body-inner .ant-table-fixed .ant-table-tbody .ant-table-row.ant-table-row-hover .ant-table-row-cell-break-word span a:nth-child(3)
        page.click(
            ".ant-table-body-inner .ant-table-fixed .ant-table-tbody .ant-table-row.ant-table-row-hover .ant-table-row-cell-break-word span a:nth-child(3)")
        # Click button:has-text("确 定")
        page.click("button:has-text(\"确 定\")")
        # Click .ant-table-body-inner .ant-table-fixed .ant-table-tbody .ant-table-row.ant-table-row-hover .ant-table-row-cell-break-word span a:nth-child(3)
        page.click(
            ".ant-table-body-inner .ant-table-fixed .ant-table-tbody .ant-table-row.ant-table-row-hover .ant-table-row-cell-break-word span a:nth-child(3)")
        # Click button:has-text("确 定")
        page.click("button:has-text(\"确 定\")")
        # Click :nth-match(:text("删除"), 4)
        page.click(":nth-match(:text(\"删除\"), 4)")
        # Click button:has-text("确 定")
        page.click("button:has-text(\"确 定\")")
        # Click text=设置负责人
        page.click("text=设置负责人")
        # assert page.url == "http://localhost:3000/deploy/command/CreateCommand#"
        # Click text=设为负责人设为负责人设为负责人设为负责人 >> a
        page.click("text=设为负责人设为负责人设为负责人设为负责人 >> a")
        # Click button:has-text("预览动员命令")
        page.click("button:has-text(\"预览动员命令\")")

    def cmdTabChange(self):
        """
        命令的 tab 该表
        :return:
        """
        page = self.page
        self.goToIssueCmdList()
        # Click text=生成中(14)
        page.click("text=生成中(14)")
        self.waitForSomeTime()
        # Click text=待下达(1)
        page.click("text=待下达(1)")
        self.waitForSomeTime()
        # Click text=执行中(5)
        page.click("text=执行中(5)")
        self.waitForSomeTime()
        # Click text=已完成(3)
        page.click("text=已完成(3)")
        self.waitForSomeTime()
        # Click text=已归档(1)
        page.click("text=已归档(1)")
        self.waitForSomeTime()
        # Click text=已作废(1)
        page.click("text=已作废(1)")

        return self

    def viewCmdDetail(self):
        """
        查看明细详情
        :return:
        """
        page = self.page

        # Click ul[role="menu"] div:has-text("系统管理")
        page.click("ul[role=\"menu\"] div:has-text(\"系统管理\")")
        # Click ul[role="menu"] div:has-text("下达动员决心")
        page.click("ul[role=\"menu\"] div:has-text(\"下达动员决心\")")
        # Click a:has-text("下达命令列表")
        page.click("a:has-text(\"下达命令列表\")")
        # Click text=全部(25)
        page.click("text=全部(25)")
        self.waitForSomeTime()
        page.click(
            "//*[@id='app']/section/section/main/div[2]/div/div/div/div[3]/div/div/div/div/div/div[2]/div/div/table/tbody/tr[2]/td/span/span[1]/a")
        # Click text=5云岩区云岩区zwb任务查看 >> a
        page.click("text=5云岩区云岩区zwb任务查看 >> a")
        # Click [aria-label="Close"]
        page.click("[aria-label=\"Close\"]")

        self.waitForSomeTime()
        # Click tr:nth-child(4) td:nth-child(6)
        page.click("tr:nth-child(4) td:nth-child(6)")
        # Click [aria-label="Close"]
        page.click("[aria-label=\"Close\"]")
        self.waitForSomeTime()
        # Click text=3花溪区花溪区zwb任务查看 >> a
        page.click("text=3花溪区花溪区zwb任务查看 >> a")
        # Click [aria-label="Close"]
        page.click("[aria-label=\"Close\"]")
        self.waitForSomeTime()
        # Click text=2乌当区白云区武部zwb任务查看 >> a
        page.click("text=2乌当区白云区武部zwb任务查看 >> a")
        # Click [aria-label="Close"]
        page.click("[aria-label=\"Close\"]")
        self.waitForSomeTime()
        # Click text=任务查看
        page.click("text=任务查看")
        # Click [aria-label="Close"]
        page.click("[aria-label=\"Close\"]")

    def doIssueCmd(self):
        """
        下达动员决心
        :return:
        """
        page = self.page
        # Click :nth-match(a:has-text("下达命令"), 4)
        page.click(":nth-match(a:has-text(\"下达命令\"), 4)")
        self.waitForSomeTime()
        # Click button:has-text("取 消")
        page.click("button:has-text(\"取 消\")")
        self.waitForSomeTime()
        # Click :nth-match(a:has-text("下达命令"), 4)
        page.click("button:has-text(\"确 定\")")
        self.waitForSomeTime()
